use tauri;
use crate::models::state::{MakeCallArgs, MakeCallResult, ConnectionResult, CallRecord};
use crate::services::call::CallService;
use crate::services::call::CallRuntimeService;

#[tauri::command]
pub async fn make_call(app: tauri::AppHandle, args: MakeCallArgs) -> Result<MakeCallResult, String> {
    CallRuntimeService::make_call(app, args).await
}

#[tauri::command]
pub async fn hangup_call() -> Result<ConnectionResult, String> {
    CallRuntimeService::hangup_call().await
}

#[tauri::command]
pub async fn get_call_history() -> Result<Vec<CallRecord>, String> {
    CallService::get_history()
        .await
        .map_err(|e| format!("获取通话记录失败: {}", e))
}

#[tauri::command]
pub async fn search_call_history(query: String) -> Result<Vec<CallRecord>, String> {
    CallService::search_history(&query)
        .await
        .map_err(|e| format!("搜索通话记录失败: {}", e))
}

